package com.jmb.apiplatform.controller;


import com.jmb.apiplatform.common.PageResult;
import com.jmb.apiplatform.common.Result;
import com.jmb.apiplatform.exception.ValidException;
import com.jmb.apiplatform.pojo.ProjectDao;
import com.jmb.apiplatform.pojo.ProjectVO;
import com.jmb.apiplatform.service.ProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "项目管理")
@Slf4j
@RequestMapping("/project")
@RestController
public class ProjectController {
    @Autowired
    private ProjectService projectService;

    @Operation(summary = "新增项目")
    @PostMapping("/save")
    public Result save(@RequestBody ProjectDao projectDao) throws ValidException {
        projectService.saveProject(projectDao);
        return Result.success("新增成功");
    }
    @Operation(summary = "项目列表")
    @GetMapping("/list")
    public Result pageList(ProjectVO projectVO){
        PageResult<ProjectDao> pageResult = projectService.listProject(projectVO);
        return Result.success(pageResult);
    }
    @Operation(summary = "删除项目")
    @GetMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) throws ValidException {
        projectService.removeById(id);
        return Result.success("删除成功");
    }

    @Operation(summary = "查找项目")
    @GetMapping("/info")
    public Result findProjectId( ProjectDao projectDao) throws ValidException {
        ProjectDao projectDaoId = projectService.finProjectId(projectDao.getProjectId());
        return Result.success(projectDaoId);
    }
    @Operation(summary = "修改项目")
    @PostMapping("/modify")
    public Result updateProject(@RequestBody ProjectDao projectDao) throws ValidException {
        projectService.updateProject(projectDao);
        return Result.success("修改成功");
    }
    @Operation(summary = "所有项目")
    @GetMapping({"/all"})
    public Result allProject(){
        return Result.success(projectService.projectList());
    }
}
